from google.appengine.ext import webapp
from google.appengine.ext.webapp import template


class UndefinedTemplate(Exception):
    pass


class BaseHandler(webapp.RequestHandler):

    template = None

    def __init__(self):
        super(webapp.RequestHandler, self).__init__()
        self.template_vars = {}

    def fill_template(self):
        if self.template:
            template_path = "../templates/%s" % self.template
            self.response.out.write(template.render(template_path, self.template_vars))
        else:
            raise UndefinedTemplate("Template not defined for handler: %s" % self.__class__.__name__)